#include <dde_kit/memory.h>

#include "conf.h"

#include <eku/stdio.h>
#include <eku/stdlib.h>

extern dde_kit_addr_t *inv_map;

struct dde_kit_slab
{
	 int size;
	 void *user_data;
};

void
dde_kit_slab_set_data(struct dde_kit_slab * slab, void *data)
{
	 slab->user_data = data;
}

void *
dde_kit_slab_get_data(struct dde_kit_slab * slab)
{
	 return slab->user_data;
}

void *
dde_kit_slab_alloc(struct dde_kit_slab * slab)
{
	 return malloc(slab->size);
}

void
dde_kit_slab_free(struct dde_kit_slab * slab, void *objp)
{
	 free(objp);
}

void
dde_kit_slab_destroy(struct dde_kit_slab * slab)
{
	 free(slab);
}

struct dde_kit_slab *
dde_kit_slab_init(unsigned size)
{
	 struct dde_kit_slab *result = (struct dde_kit_slab *)
		  malloc(sizeof(struct dde_kit_slab));
	 result->user_data = 0;
	 result->size = size;
	 return result;
}

void *
dde_kit_large_malloc(dde_kit_size_t size)
{
	 return pmalloc(size, 1);
}


void
dde_kit_large_free(void *p)
{
	 pfree(p);
}


void *
dde_kit_simple_malloc(dde_kit_size_t size)
{
	 return malloc(size);
}

void
dde_kit_simple_free(void *p)
{
	 if (p != NULL) free(p);
}

#include <eku/symbol.h>

void
dde_kit_memory_symbol(void)
{
	 export_symbol("dde_kit_slab_alloc", &dde_kit_slab_alloc, 1);
	 export_symbol("dde_kit_slab_free", &dde_kit_slab_free, 1);
	 export_symbol("dde_kit_slab_get_data", &dde_kit_slab_get_data, 1);
	 export_symbol("dde_kit_slab_set_data", &dde_kit_slab_set_data, 1);
	 export_symbol("dde_kit_slab_init", &dde_kit_slab_init, 1);
	 export_symbol("dde_kit_slab_destroy", &dde_kit_slab_destroy, 1);
	 export_symbol("dde_kit_large_malloc", &dde_kit_large_malloc, 1);
	 export_symbol("dde_kit_large_free", &dde_kit_large_free, 1);
	 export_symbol("dde_kit_simple_malloc", &dde_kit_simple_malloc, 1);
	 export_symbol("dde_kit_simple_free", &dde_kit_simple_free, 1);
}
